package com.dede.lib2;

import org.jaudiotagger.audio.AudioFile;
import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.audio.exceptions.CannotReadException;
import org.jaudiotagger.audio.exceptions.CannotWriteException;
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
import org.jaudiotagger.tag.FieldKey;
import org.jaudiotagger.tag.Tag;
import org.jaudiotagger.tag.TagException;

import java.io.File;
import java.io.IOException;

public class myClass {

    static String path1 = "D:\\CloudMusic\\那英,王菲 - 相约一九九八.mp3";
    static String path = "C:\\Users\\Administrator\\Desktop\\test - 副本.mp3";

    public static void main(String... args) {
        try {

            AudioFile f = AudioFileIO.read(new File(path));
            Tag tag = f.getTag();
            tag.setField(FieldKey.TITLE, "落地开花");
            tag.setField(FieldKey.ARTIST, "卢巧音");
            tag.setField(FieldKey.ALBUM, "落地开花");
            AudioFileIO.write(f);


            tag = f.getTag();
            System.out.println(tag.getFirst(FieldKey.ARTIST));
            System.out.println(tag.getFirst(FieldKey.ALBUM));
            System.out.println(tag.getFirst(FieldKey.TITLE));
            System.out.println(tag.getFirst(FieldKey.COMMENT));
            System.out.println(tag.getFirst(FieldKey.YEAR));
            System.out.println(tag.getFirst(FieldKey.TRACK));
            System.out.println(tag.getFirst(FieldKey.DISC_NO));
            System.out.println(tag.getFirst(FieldKey.COMPOSER));
            System.out.println(tag.getFirst(FieldKey.ARTIST_SORT));

        } catch (IOException e) {
            e.printStackTrace();
        } catch (TagException e) {
            e.printStackTrace();
        } catch (ReadOnlyFileException e) {
            e.printStackTrace();
        } catch (InvalidAudioFrameException e) {
            e.printStackTrace();
        } catch (CannotReadException e) {
            e.printStackTrace();
        } catch (CannotWriteException e) {
            e.printStackTrace();
        }
    }
}
